{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "/var/folders/5k/blch4xw910dcskrtzns2bjz00000gn/T/ipykernel_4165/2746749078.py:1: DeprecationWarning: 'telnetlib' is deprecated and slated for removal in Python 3.13\n",
      "  from telnetlib import Telnet\n"
     ]
    }
   ],
   "source": [
    "from telnetlib import Telnet"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "def cmdline(tn,cmd):\n",
    "    tn.write(cmd)\n",
    "    ret = tn.read_until(b\"root@ai_prj:~# \")\n",
    "    print(f\"done: \\n{ret.decode('ascii')}\")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "done: cp /run/media/mmcblk0p1/*.txt .\n",
      "root@ai_prj:~# \n",
      "done: cp /run/media/mmcblk0p1/run_all.sh .\n",
      "root@ai_prj:~# \n",
      "done: sh run_all.sh\n",
      "insmod: can't insert '/lib/modules/5.15.19-xilinx-v2022.1/extra/simple-drv.ko': File exists\n",
      "config PLL !! \n",
      "configure AD9371 \n",
      "All PLLs locked!\n",
      "AD9371 Config Over \n",
      "\n",
      "configure AD9371 \n",
      "All PLLs locked!\n",
      "AD9371 Config Over \n",
      "\n",
      "Set the RX  Frequecy @ 1000000000  TX Frequency @ 2000000000 \n",
      "x Freq  = 1000000000 & Tx Freq = 2000000000 \n",
      "Set the RF  TX attan \n",
      "att1 = 32768,  att2 = 32768\n",
      "Set the RX  Frequecy @ 1000000000  TX Frequency @ 2000000000 \n",
      "x Freq  = 1000000000 & Tx Freq = 2000000000 \n",
      "Set the RF  TX attan \n",
      "att1 = 32768,  att2 = 32768\n",
      "Set Dac  Level = < 360 >  in AUX Dac [0] \n",
      "Read and set the FFT filters \n",
      "****************************line [0] ***************************************\n",
      "freq_cent = 1000000000 -- freq_start = 985000000  -- freq_stop = 1015000000 -- filt_type = 1 \n",
      "filter_start = -15000000, filter_stop = 15000000 \n",
      "N_start = -500, N_stop = 500 \n",
      "************************************************************************\n",
      "Success fft_fir_ana  0 \n",
      "****************************line [0] ***************************************\n",
      "freq_cent = 1000000000 -- freq_start = 950000000  -- freq_stop = 1000000000 -- filt_type = 1 \n",
      "filter_start = -50000000, filter_stop = 0 \n",
      "N_start = -1666, N_stop = 0 \n",
      "************************************************************************\n",
      "Success fft_fir_ana   1\n",
      "****************************line [0] ***************************************\n",
      "freq_cent = 1000000000 -- freq_start = 950000000  -- freq_stop = 1000000000 -- filt_type = 1 \n",
      "filter_start = -50000000, filter_stop = 0 \n",
      "N_start = -1666, N_stop = 0 \n",
      "************************************************************************\n",
      "Success fft_fir_ana  2 \n",
      "****************************line [0] ***************************************\n",
      "freq_cent = 1000000000 -- freq_start = 950000000  -- freq_stop = 1000000000 -- filt_type = 1 \n",
      "filter_start = -50000000, filter_stop = 0 \n",
      "N_start = -1666, N_stop = 0 \n",
      "************************************************************************\n",
      "Success fft_fir_ana  3 \n",
      "****************************line [0] ***************************************\n",
      "freq_cent = 1000000000 -- freq_start = 950000000  -- freq_stop = 1000000000 -- filt_type = 1 \n",
      "filter_start = -50000000, filter_stop = 0 \n",
      "N_start = -1666, N_stop = 0 \n",
      "************************************************************************\n",
      "Success fft_fir_ana   44\n",
      "****************************line [0] ***************************************\n",
      "freq_cent = 1000000000 -- freq_start = 950000000  -- freq_stop = 1000000000 -- filt_type = 1 \n",
      "filter_start = -50000000, filter_stop = 0 \n",
      "N_start = -1666, N_stop = 0 \n",
      "************************************************************************\n",
      "Success fft_fir_ana   5\n",
      "****************************line [0] ***************************************\n",
      "freq_cent = 1000000000 -- freq_start = 950000000  -- freq_stop = 1000000000 -- filt_type = 1 \n",
      "filter_start = -50000000, filter_stop = 0 \n",
      "N_start = -1666, N_stop = 0 \n",
      "************************************************************************\n",
      "Success fft_fir_ana  6 \n",
      "****************************line [0] ***************************************\n",
      "freq_cent = 1000000000 -- freq_start = 950000000  -- freq_stop = 1000000000 -- filt_type = 1 \n",
      "filter_start = -50000000, filter_stop = 0 \n",
      "N_start = -1666, N_stop = 0 \n",
      "************************************************************************\n",
      "Success fft_fir_ana  7 \n",
      "root@ai_prj:~# \n"
     ]
    }
   ],
   "source": [
    "with Telnet('192.168.1.100') as tn:\n",
    "    tn.read_until(b\"login: \")\n",
    "    tn.write(b\"root\\n\")\n",
    "    tn.read_until(b\"Password: \")\n",
    "    tn.write(b\"root\\n\")\n",
    "    tn.read_until(b\"root@ai_prj:~# \")\n",
    "    cmdline(tn,b\"cp /run/media/mmcblk0p1/*.txt .\\n\")\n",
    "    cmdline(tn,b\"cp /run/media/mmcblk0p1/run_all.sh .\\n\")\n",
    "    cmdline(tn,b\"sh run_all.sh\\n\")\n",
    "    tn.close()\n",
    "    \n",
    "    "
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3.11.3 64-bit",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.11.3"
  },
  "orig_nbformat": 4,
  "vscode": {
   "interpreter": {
    "hash": "b0fa6594d8f4cbf19f97940f81e996739fb7646882a419484c72d19e05852a7e"
   }
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
